package com.heima.wemedia.scan.job;

import com.heima.model.wemedia.entity.WmNews;
import com.heima.wemedia.scan.dao.WmNewsDao;
import com.heima.wemedia.scan.service.WmNewsAutoScanService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
@Slf4j
public class XxlArticleJob {

    @Resource
    private WmNewsDao wmNewsDao;

    @Resource
    private WmNewsAutoScanService wmNewsAutoScanService;

    /**
     * 定时扫描待发布的文章
     */
    @XxlJob("newsAutoPushJob")
    public void scanWmNews() {
        log.info("开始扫描需要发布的文章---------");
        //1.查询需要发布的文章列表   1）文章状态为 4和 8的  2）发布时间小于当前时间的
        List<WmNews> wmNewsList = wmNewsDao.queryReleaseNews();
        //2.调用发布文章方法
        wmNewsList.forEach(wmNews -> wmNewsAutoScanService.saveApArticle(wmNews));
        log.info("扫描发布文章完成---------");
    }
}
